package com.panshi.controller.qa;

import com.panshi.api.IMessagApi;
import com.panshi.api.IReplyAuditApi;
import com.panshi.vo.qa.DataResultQA;
import com.panshi.vo.qa.Messag;
import com.panshi.vo.qa.Pages;
import com.panshi.vo.qa.ReplyAudit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
public class ReplyAuditController {
    @Autowired
    IReplyAuditApi replyAuditApi;

   /* @Autowired
    IRabbitMQApi rabbitMQApi;*/

   @Autowired
   IMessagApi messagApi;



    /*IReplyAudit(回答审核)*/

    /**
     * 添加回答
     * @param replyAudit
     * @return
     */
    @PostMapping("/replyAudit/add")
    @ResponseBody
    DataResultQA addReplyAudit(@RequestBody ReplyAudit replyAudit){
        DataResultQA dataResultQA = replyAuditApi.addReplyAudit(replyAudit);

        if(dataResultQA.isBoo()){//发送站内消息
            Messag messag = new Messag();
            //用户id
            messag.setUserId(replyAudit.getRUserId());
            //回答
            messag.setTitle(replyAudit.getRContent());
            //表示文章类型
            messag.setCheckType(Messag.REPLY_TYPE);

            messagApi.addMessag(messag);
        }

        return dataResultQA;
    }

    /**
     * 分页查询
     * @param pages
     * @return
     */
    @PostMapping("/replyAudit/inquirePages")
    @ResponseBody
    DataResultQA<Pages<ReplyAudit>> inquireReplyAuditPages(@RequestBody Pages pages){
        DataResultQA<Pages<ReplyAudit>> dataResultQA = replyAuditApi.inquireReplyAuditPages(pages);
        return dataResultQA;
    }

    /**
     * 查询总记录数
     * @param pages
     * @return
     */
    @GetMapping("/replyAudit/inquireSum")
    @ResponseBody
    DataResultQA<Integer> inquireReplyAuditSum(@RequestParam Pages pages){
        DataResultQA<Integer> dataResultQA = replyAuditApi.inquireReplyAuditSum(pages);
        return dataResultQA;
    }

    /**
     * 通过id查询回答
     * @param id
     * @return
     */
    @PostMapping("/replyAudit/inquireById/{id}")
    @ResponseBody
    DataResultQA<ReplyAudit> inquireByIdReplyAudit(@PathVariable int id){
        DataResultQA<ReplyAudit> dataResultQA = replyAuditApi.inquireByIdReplyAudit(id);
        return dataResultQA;
    }

    /**
     * 修改内容（用户）
     * @param replyAudit
     * @return
     */
    @PostMapping("/replyAudit/update")
    @ResponseBody
    DataResultQA updateReplyAudit(@RequestBody ReplyAudit replyAudit){
        DataResultQA dataResultQA = replyAuditApi.updateReplyAudit(replyAudit);
        return dataResultQA;
    }

    /**
     * 删除(标记删除)
     * @param id
     * @return
     */
    @GetMapping("/replyAudit/delete/{id}")
    @ResponseBody
    DataResultQA deleteReplyAudit(@PathVariable int id){
        DataResultQA dataResultQA = replyAuditApi.deleteReplyAudit(id);
        return dataResultQA;
    }

    /**
     * 修改审核状态<审核>（管理员）
     * @param replyAudit
     * @return
     */
    @GetMapping("/replyAudit/updateState")
    @ResponseBody
    DataResultQA updateStateReplyAudit(@RequestParam ReplyAudit replyAudit){

        DataResultQA dataResultQA = replyAuditApi.updateStateReplyAudit(replyAudit);

        //rabbitmq发送邮件
        /*if (dataResultQA.isBoo()){
            rabbitMQApi.sendReplyAudit(replyAudit);
        }*/

        return dataResultQA;
    }
}
